package org.study.javafx.study01.calculator.xml.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Administrator
 */
@Slf4j
public class CalculatorController {
    @FXML
    private Label result;
    @FXML
    private Label expression;

    @FXML
    public void onClicked(ActionEvent event) {
        // 获取点击的按钮
        Button button = (Button) event.getTarget();
        String input = button.getText();
        log.info("输入的值：{}", input);
        // 获取输出控件值
        String resultText = result.getText();
        try {
            int intinput = Integer.parseInt(input);
            if (resultText.length() >= 10) {
                return;
            }
            long newVal = Long.parseLong(resultText) * 10 + intinput;
            // 展示到输出区
            result.setText(newVal + "");
        } catch (Exception ex) {
            log.error("异常", ex);
            result.setText("error");
        }
    }
}
